//
//  ShopConditionToolBar.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/8.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "ShopConditionToolBar.h"

@interface ShopConditionToolBar()

@property (nonatomic,weak) SortBtn *lastSelectBtn;

@end
@implementation ShopConditionToolBar

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        NSArray *titles = @[@"按距离排序",@"按好评排序",@"按价格排序"];
        float btnW = (ScreenW-0.6)/3.0;
        for (int i=0; i<3; i++) {
            SortBtn *btn = [[SortBtn alloc]initWithFrame:CGRectMake((btnW+0.3)*i, 0, btnW, 40)];
            [btn setTitle:titles[i] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [btn setTitleColor:WineColor forState:UIControlStateSelected];
            btn.titleLabel.font = Font(16);
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag = i+1;
            [self addSubview:btn];
            if (i == 2) {
                UIView *horLine = [[UIView alloc]initWithFrame:CGRectMake(0, self.height-0.3, ScreenW, 0.3)];
                horLine.backgroundColor = [UIColor lightGrayColor];
                [self addSubview:horLine];
            }else{
                UIView *verLine = [[UIView alloc]initWithFrame:CGRectMake(btnW+(btnW+0.3)*i, 5, 0.3, self.height-10)];
                verLine.backgroundColor = [UIColor lightGrayColor];
                [self addSubview:verLine];
            }
        }
    }
    return self;
}
//原则选中是升序 反之降序  点了其它按钮后其余按钮取消选中状态
- (void)btnClick:(SortBtn *)btn
{
    btn.selected = YES;
    btn.isAsc = !btn.isAsc;
    if (self.lastSelectBtn != btn) {
        self.lastSelectBtn.selected = NO;
        self.lastSelectBtn.isAsc = NO;
        self.lastSelectBtn = btn;
    }
    if ([self.delegate respondsToSelector:@selector(shopConditionToolBarClick:aDType:)]) {
        [self.delegate shopConditionToolBarClick:(ConditionType)btn.tag aDType:btn.isAsc?AdTypeAsc:AdTypeDes];
    }
}

@end
